class Storage {
  getStorage(key: string) {
    let data = window.localStorage.getItem(key)
    try {
      if (data) {
        data = JSON.parse(data)
      }
      return data
    } catch (error) {
      return data
    }
  }
  setStorage(key: string, val: any) {
    if (val && typeof val === 'object') {
      val = JSON.stringify(val)
    }
    window.localStorage.setItem(key, val)
  }
  removeStorage(key: string) {
    window.localStorage.removeItem(key)
  }
  clearStorage() {
    window.localStorage.clear()
  }
}

export default new Storage()
